package com.github.cyf.common.module.exception;

import com.github.cyf.common.module.response.ResponseCodeEnum;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class BizException extends RuntimeException {

    /**
     * 错误码
     */
    private ResponseCodeEnum errorCode;

    /**
     * 自定义错误信息，用于前端展示
     */
    private String errorMsg;

    public BizException() {
    }

    public BizException(ResponseCodeEnum errorCode) {
        this(errorCode, errorCode.getDescription());
    }

    public BizException(ResponseCodeEnum errorCode, String errorMsg) {
        super(errorMsg);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public BizException(ResponseCodeEnum errorCode, Throwable throwable) {
        this(errorCode, errorCode.getDescription(), throwable);
    }

    public BizException(ResponseCodeEnum errorCode, String errorMsg, Throwable throwable) {
        super(throwable);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

}